<?php

/**
 * Fournisseur filter form base class.
 *
 * @package    SdCommerce
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 29570 2010-05-21 14:49:47Z Kris.Wallsmith $
 */
abstract class BaseFournisseurFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'code'                             => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'matricule_fiscale'                => new sfWidgetFormFilterInput(),
      'raison_sociale'                   => new sfWidgetFormFilterInput(),
      'telephone1'                       => new sfWidgetFormFilterInput(),
      'telephone2'                       => new sfWidgetFormFilterInput(),
      'fax'                              => new sfWidgetFormFilterInput(),
      'email'                            => new sfWidgetFormFilterInput(),
      'site_web'                         => new sfWidgetFormFilterInput(),
      'code_douane'                      => new sfWidgetFormFilterInput(),
      'numero_exoneration_tva'           => new sfWidgetFormFilterInput(),
      'date_naissance'                   => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'date_changement_categorie_remise' => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'image'                            => new sfWidgetFormFilterInput(),
      'observation'                      => new sfWidgetFormFilterInput(),
      'gsm'                              => new sfWidgetFormFilterInput(),
      'numero_agrement'                  => new sfWidgetFormFilterInput(),
      'nom'                              => new sfWidgetFormFilterInput(),
      'prenom'                           => new sfWidgetFormFilterInput(),
      'fidele'                           => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'id_forme_juridique'               => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('FormeJuridique'), 'add_empty' => true)),
      'id_nationalite'                   => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Nationalite'), 'add_empty' => true)),
      'civilite'                         => new sfWidgetFormChoice(array('choices' => array('' => '', 'M' => 'M', 'Mme' => 'Mme', 'Mlle' => 'Mlle'))),
      'id_modalite_paiement'             => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('ModalitePaiement'), 'add_empty' => true)),
      'bloquer'                          => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'created_at'                       => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'updated_at'                       => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'objectifs_list'                   => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Objectif')),
      'm_articles_list'                  => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Article')),
      'tarifs_list'                      => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Tarif')),
    ));

    $this->setValidators(array(
      'code'                             => new sfValidatorPass(array('required' => false)),
      'matricule_fiscale'                => new sfValidatorPass(array('required' => false)),
      'raison_sociale'                   => new sfValidatorPass(array('required' => false)),
      'telephone1'                       => new sfValidatorPass(array('required' => false)),
      'telephone2'                       => new sfValidatorPass(array('required' => false)),
      'fax'                              => new sfValidatorPass(array('required' => false)),
      'email'                            => new sfValidatorPass(array('required' => false)),
      'site_web'                         => new sfValidatorPass(array('required' => false)),
      'code_douane'                      => new sfValidatorPass(array('required' => false)),
      'numero_exoneration_tva'           => new sfValidatorPass(array('required' => false)),
      'date_naissance'                   => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDateTime(array('required' => false)))),
      'date_changement_categorie_remise' => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDateTime(array('required' => false)))),
      'image'                            => new sfValidatorPass(array('required' => false)),
      'observation'                      => new sfValidatorPass(array('required' => false)),
      'gsm'                              => new sfValidatorPass(array('required' => false)),
      'numero_agrement'                  => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'nom'                              => new sfValidatorPass(array('required' => false)),
      'prenom'                           => new sfValidatorPass(array('required' => false)),
      'fidele'                           => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'id_forme_juridique'               => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('FormeJuridique'), 'column' => 'id')),
      'id_nationalite'                   => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Nationalite'), 'column' => 'id')),
      'civilite'                         => new sfValidatorChoice(array('required' => false, 'choices' => array('M' => 'M', 'Mme' => 'Mme', 'Mlle' => 'Mlle'))),
      'id_modalite_paiement'             => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('ModalitePaiement'), 'column' => 'id')),
      'bloquer'                          => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'created_at'                       => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'updated_at'                       => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'objectifs_list'                   => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Objectif', 'required' => false)),
      'm_articles_list'                  => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Article', 'required' => false)),
      'tarifs_list'                      => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Tarif', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('fournisseur_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addObjectifsListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.ObjectifFournisseur ObjectifFournisseur')
      ->andWhereIn('ObjectifFournisseur.id_objectif', $values)
    ;
  }

  public function addMArticlesListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.ArticleFournisseur ArticleFournisseur')
      ->andWhereIn('ArticleFournisseur.article_id', $values)
    ;
  }

  public function addTarifsListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.TarifFournisseur TarifFournisseur')
      ->andWhereIn('TarifFournisseur.id_tarif', $values)
    ;
  }

  public function getModelName()
  {
    return 'Fournisseur';
  }

  public function getFields()
  {
    return array(
      'id'                               => 'Number',
      'code'                             => 'Text',
      'matricule_fiscale'                => 'Text',
      'raison_sociale'                   => 'Text',
      'telephone1'                       => 'Text',
      'telephone2'                       => 'Text',
      'fax'                              => 'Text',
      'email'                            => 'Text',
      'site_web'                         => 'Text',
      'code_douane'                      => 'Text',
      'numero_exoneration_tva'           => 'Text',
      'date_naissance'                   => 'Date',
      'date_changement_categorie_remise' => 'Date',
      'image'                            => 'Text',
      'observation'                      => 'Text',
      'gsm'                              => 'Text',
      'numero_agrement'                  => 'Number',
      'nom'                              => 'Text',
      'prenom'                           => 'Text',
      'fidele'                           => 'Boolean',
      'id_forme_juridique'               => 'ForeignKey',
      'id_nationalite'                   => 'ForeignKey',
      'civilite'                         => 'Enum',
      'id_modalite_paiement'             => 'ForeignKey',
      'bloquer'                          => 'Boolean',
      'created_at'                       => 'Date',
      'updated_at'                       => 'Date',
      'objectifs_list'                   => 'ManyKey',
      'm_articles_list'                  => 'ManyKey',
      'tarifs_list'                      => 'ManyKey',
    );
  }
}
